<!DOCTYPE html>
<html lang=zh>
<head>
  <meta charset="utf-8">
  
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no, minimal-ui">
  <meta name="renderer" content="webkit">
  <meta http-equiv="Cache-Control" content="no-transform" />
  <meta http-equiv="Cache-Control" content="no-siteapp" />
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-status-bar-style" content="black">
  <meta name="format-detection" content="telephone=no,email=no,adress=no">
  <!-- Color theme for statusbar -->
  <meta name="theme-color" content="#000000" />
  <!-- 强制页面在当前窗口以独立页面显示,防止别人在框架里调用页面 -->
  <meta http-equiv="window-target" content="_top" />
  
  
  <title>gitee-jenkins自动化构建部署 | 雨落</title>
  <meta name="description" content="前端自动化部署gitee + Jenkins自动构建前端项目并部署到服务器 Gitea 用于构建 Git 局域网服务器，Jenkins 是 CI&#x2F;CD 工具，用于部署前端项目。  配置Gitee 下载Gitea，选择版本，例如：gitea-1.13-windows-4.0-amd64.exe 下载。 下载完后，新建一个目录（例如 gitea），将下载的 Gitea 软件放到该目录下，双击运行。">
<meta property="og:type" content="article">
<meta property="og:title" content="gitee-jenkins自动化构建部署">
<meta property="og:url" content="https://gitee.com/Yu-Luoboke/2021/03/19/gitee-jenkins%E8%87%AA%E5%8A%A8%E5%8C%96%E6%9E%84%E5%BB%BA%E9%83%A8%E7%BD%B2/index.html">
<meta property="og:site_name" content="雨落">
<meta property="og:description" content="前端自动化部署gitee + Jenkins自动构建前端项目并部署到服务器 Gitea 用于构建 Git 局域网服务器，Jenkins 是 CI&#x2F;CD 工具，用于部署前端项目。  配置Gitee 下载Gitea，选择版本，例如：gitea-1.13-windows-4.0-amd64.exe 下载。 下载完后，新建一个目录（例如 gitea），将下载的 Gitea 软件放到该目录下，双击运行。">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://gitee.com/blog/images/gitee1.png">
<meta property="og:image" content="https://gitee.com/blog/images/gitee1.png">
<meta property="og:image" content="https://gitee.com/blog/images/serverSSH.png">
<meta property="og:image" content="https://gitee.com/blog/images/Jenkins-download.png">
<meta property="og:image" content="https://gitee.com/blog/images/Logon.png">
<meta property="og:image" content="https://gitee.com/blog/images/seljdk.png">
<meta property="og:image" content="https://gitee.com/blog/images/slor.png">
<meta property="og:image" content="https://gitee.com/blog/images/plugin.png">
<meta property="og:image" content="https://gitee.com/blog/images/selPlugin.png">
<meta property="og:image" content="https://gitee.com/blog/images/d.png">
<meta property="og:image" content="https://gitee.com/blog/images/nodejs.png">
<meta property="og:image" content="https://gitee.com/blog/images/gitea.png">
<meta property="og:image" content="https://gitee.com/blog/images/newitem.png">
<meta property="og:image" content="https://gitee.com/blog/images/copy.png">
<meta property="og:image" content="https://gitee.com/blog/images/auto.png">
<meta property="og:image" content="https://gitee.com/blog/images/node.png">
<meta property="og:image" content="https://gitee.com/blog/images/select.png">
<meta property="og:image" content="https://gitee.com/blog/images/dist.png">
<meta property="og:image" content="https://gitee.com/blog/images/build.png">
<meta property="og:image" content="https://gitee.com/blog/images/startbuild.png">
<meta property="og:image" content="https://gitee.com/blog/images/success.png">
<meta property="og:image" content="https://gitee.com/blog/images/buildsuccess.png">
<meta property="og:image" content="https://gitee.com/blog/images/resetbuild.png">
<meta property="og:image" content="https://gitee.com/blog/images/set.png">
<meta property="og:image" content="https://gitee.com/blog/images/token.png">
<meta property="og:image" content="https://gitee.com/blog/images/renwu.png">
<meta property="og:image" content="https://gitee.com/blog/images/shuru.png">
<meta property="og:image" content="https://gitee.com/blog/images/baocun.png">
<meta property="og:image" content="https://gitee.com/blog/images/22.png">
<meta property="og:image" content="https://gitee.com/blog/images/promission.png">
<meta property="og:image" content="https://gitee.com/blog/images/%E6%8E%88%E6%9D%83.png">
<meta property="og:image" content="https://gitee.com/blog/images/%E4%BB%93%E5%BA%93%E8%AE%BE%E7%BD%AE.png">
<meta property="og:image" content="https://gitee.com/blog/images/%E6%B7%BB%E5%8A%A0.png">
<meta property="article:published_time" content="2021-03-19T07:30:01.000Z">
<meta property="article:modified_time" content="2021-04-21T02:49:06.130Z">
<meta property="article:author" content="lianghongming">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://gitee.com/blog/images/gitee1.png">
  <!-- Canonical links -->
  <link rel="canonical" href="https://gitee.com/Yu-Luoboke/2021/03/19/gitee-jenkins%E8%87%AA%E5%8A%A8%E5%8C%96%E6%9E%84%E5%BB%BA%E9%83%A8%E7%BD%B2/index.html">
  
    <link rel="alternate" href="/atom.xml" title="雨落" type="application/atom+xml">
  
  
    <link rel="icon" href="/favicon.png" type="image/x-icon">
  
  
<link rel="stylesheet" href="/blog/css/style.css">

  
  
  
  
<meta name="generator" content="Hexo 5.2.0"></head>


<body class="main-center" itemscope itemtype="http://schema.org/WebPage">
  <header class="header" itemscope itemtype="http://schema.org/WPHeader">
  <div class="slimContent">
    <div class="navbar-header">
      
      
      <div class="profile-block text-center">
        <a id="avatar" href="http://yu-luoboke.gitee.io/blog" target="_blank">
          <img class="img-circle img-rotate" src="/blog/images/avatar.jpg" width="200" height="200">
        </a>
        <h2 id="name" class="hidden-xs hidden-sm">雨落</h2>
        <h3 id="title" class="hidden-xs hidden-sm hidden-md">前端开发-奋斗青年</h3>
        <small id="location" class="text-muted hidden-xs hidden-sm"><i class="icon icon-map-marker"></i> GuangZhou, China</small>
      </div>
      
      <div class="search" id="search-form-wrap">

    <form class="search-form sidebar-form">
        <div class="input-group">
            <input type="text" class="search-form-input form-control" placeholder="搜索" />
            <span class="input-group-btn">
                <button type="submit" class="search-form-submit btn btn-flat" onclick="return false;"><i class="icon icon-search"></i></button>
            </span>
        </div>
    </form>
    <div class="ins-search">
  <div class="ins-search-mask"></div>
  <div class="ins-search-container">
    <div class="ins-input-wrapper">
      <input type="text" class="ins-search-input" placeholder="想要查找什么..." x-webkit-speech />
      <button type="button" class="close ins-close ins-selectable" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
    </div>
    <div class="ins-section-wrapper">
      <div class="ins-section-container"></div>
    </div>
  </div>
</div>


</div>
      <button class="navbar-toggle collapsed" type="button" data-toggle="collapse" data-target="#main-navbar" aria-controls="main-navbar" aria-expanded="false">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
    </div>
    <nav id="main-navbar" class="collapse navbar-collapse" itemscope itemtype="http://schema.org/SiteNavigationElement" role="navigation">
      <ul class="nav navbar-nav main-nav menu-highlight">
        
        
        <li class="menu-item menu-item-home">
          <a href="/blog/.">
            
            <i class="icon icon-home-fill"></i>
            
            <span class="menu-title">首页</span>
          </a>
        </li>
        
        
        <li class="menu-item menu-item-archives">
          <a href="/blog/archives">
            
            <i class="icon icon-archives-fill"></i>
            
            <span class="menu-title">归档</span>
          </a>
        </li>
        
        
        <li class="menu-item menu-item-categories">
          <a href="/blog/categories">
            
            <i class="icon icon-folder"></i>
            
            <span class="menu-title">分类</span>
          </a>
        </li>
        
        
        <li class="menu-item menu-item-tags">
          <a href="/blog/tags">
            
            <i class="icon icon-tags"></i>
            
            <span class="menu-title">标签</span>
          </a>
        </li>
        
      </ul>
      
	
    <ul class="social-links">
    	
        <li><a href="http://yu-luoboke.gitee.io/blog" target="_blank" title="Github" ><i class="icon icon-github"></i></a></li>
        
    </ul>

    </nav>
  </div>
</header>

  
    <aside class="sidebar" itemscope itemtype="http://schema.org/WPSideBar">
  <div class="slimContent">
    
      <div class="widget">
    <h3 class="widget-title">公告</h3>
    <div class="widget-body">
        <div id="board">
            <div class="content">
                <p>欢迎交流与分享经验!</p>
            </div>
        </div>
    </div>
</div>

    
      
  <div class="widget">
    <h3 class="widget-title">分类</h3>
    <div class="widget-body">
      <ul class="category-list"><li class="category-list-item"><a class="category-list-link" href="/blog/categories/Git/">Git</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/HTML-CSS/">HTML + CSS</a><span class="category-list-count">7</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/JVM%EF%BC%88Java%E8%99%9A%E6%8B%9F%E6%9C%BA%EF%BC%89-%E5%9E%83%E5%9C%BE%E5%9B%9E%E6%94%B6%E7%AE%97%E6%B3%95/">JVM（Java虚拟机）-垃圾回收算法</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/Node/">Node</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/Project/">Project</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/React/">React</a><span class="category-list-count">4</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/SVN/">SVN</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/Vue-typescript/">Vue-typescript</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/gitee/">gitee</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/iOS/">iOS</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/js/">js</a><span class="category-list-count">12</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/vue/">vue</a><span class="category-list-count">13</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/web-serve%E9%9D%99%E6%80%81%E8%B5%84%E6%BA%90%E6%9C%8D%E5%8A%A1%E5%99%A8/">web serve静态资源服务器</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/webpack/">webpack</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/%E5%89%8D%E7%AB%AF%E8%87%AA%E5%8A%A8%E5%8C%96/">前端自动化</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/%E5%B0%8F%E7%A8%8B%E5%BA%8F/">小程序</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/%E7%A7%BB%E5%8A%A8%E7%AB%AF/">移动端</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/%E7%BB%8F%E9%AA%8C/">经验</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/%E9%9D%A2%E8%AF%95%E9%A2%98/">面试题</a><span class="category-list-count">4</span></li></ul>
    </div>
  </div>


    
      

    
      
    
      
  <div class="widget">
    <h3 class="widget-title">归档</h3>
    <div class="widget-body">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2024/04/">四月 2024</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2023/11/">十一月 2023</a><span class="archive-list-count">8</span></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2023/09/">九月 2023</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2022/12/">十二月 2022</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2022/08/">八月 2022</a><span class="archive-list-count">3</span></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2022/07/">七月 2022</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2022/06/">六月 2022</a><span class="archive-list-count">4</span></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2022/04/">四月 2022</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2022/01/">一月 2022</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2021/12/">十二月 2021</a><span class="archive-list-count">4</span></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2021/11/">十一月 2021</a><span class="archive-list-count">3</span></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2021/10/">十月 2021</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2021/04/">四月 2021</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2021/03/">三月 2021</a><span class="archive-list-count">3</span></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2021/02/">二月 2021</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2021/01/">一月 2021</a><span class="archive-list-count">6</span></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2020/12/">十二月 2020</a><span class="archive-list-count">15</span></li></ul>
    </div>
  </div>


    
      
  <div class="widget">
    <h3 class="widget-title">最新文章</h3>
    <div class="widget-body">
      <ul class="recent-post-list list-unstyled no-thumbnail">
        
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                <a class="category-link" href="/blog/categories/HTML-CSS/">HTML + CSS</a>
              </p>
              <p class="item-title">
                <a href="/blog/2024/04/15/%E6%8B%96%E5%8A%A8%E5%92%8C%E7%82%B9%E5%87%BB%E5%BC%B9%E7%AA%97/" class="title">拖动和点击弹窗</a>
              </p>
              <p class="item-date">
                <time datetime="2024-04-15T12:22:06.000Z" itemprop="datePublished">2024-04-15</time>
              </p>
            </div>
          </li>
          
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                <a class="category-link" href="/blog/categories/%E9%9D%A2%E8%AF%95%E9%A2%98/">面试题</a>
              </p>
              <p class="item-title">
                <a href="/blog/2023/11/29/html%E9%9D%A2%E8%AF%95%E9%A2%98/" class="title">html面试题</a>
              </p>
              <p class="item-date">
                <time datetime="2023-11-29T15:58:27.000Z" itemprop="datePublished">2023-11-29</time>
              </p>
            </div>
          </li>
          
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                <a class="category-link" href="/blog/categories/%E9%9D%A2%E8%AF%95%E9%A2%98/">面试题</a>
              </p>
              <p class="item-title">
                <a href="/blog/2023/11/29/css%E9%9D%A2%E8%AF%95%E9%A2%98/" class="title">css面试题</a>
              </p>
              <p class="item-date">
                <time datetime="2023-11-29T15:57:17.000Z" itemprop="datePublished">2023-11-29</time>
              </p>
            </div>
          </li>
          
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                <a class="category-link" href="/blog/categories/%E9%9D%A2%E8%AF%95%E9%A2%98/">面试题</a>
              </p>
              <p class="item-title">
                <a href="/blog/2023/11/29/js%E9%9D%A2%E8%AF%95%E9%A2%98/" class="title">js面试题</a>
              </p>
              <p class="item-date">
                <time datetime="2023-11-29T15:37:30.000Z" itemprop="datePublished">2023-11-29</time>
              </p>
            </div>
          </li>
          
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                <a class="category-link" href="/blog/categories/%E9%9D%A2%E8%AF%95%E9%A2%98/">面试题</a>
              </p>
              <p class="item-title">
                <a href="/blog/2023/11/29/%E9%9D%A2%E8%AF%95%E9%A2%98/" class="title">面试题</a>
              </p>
              <p class="item-date">
                <time datetime="2023-11-29T15:29:49.000Z" itemprop="datePublished">2023-11-29</time>
              </p>
            </div>
          </li>
          
      </ul>
    </div>
  </div>
  

    
  </div>
</aside>

  
  
<main class="main" role="main">
  <div class="content">
  <article id="post-gitee-jenkins自动化构建部署" class="article article-type-post" itemscope itemtype="http://schema.org/BlogPosting">
    
    <div class="article-header">
      
        
  
    <h1 class="article-title" itemprop="name">
      gitee-jenkins自动化构建部署
    </h1>
  

      
      <div class="article-meta">
        <span class="article-date">
    <i class="icon icon-calendar-check"></i>
	<a href="/blog/2021/03/19/gitee-jenkins%E8%87%AA%E5%8A%A8%E5%8C%96%E6%9E%84%E5%BB%BA%E9%83%A8%E7%BD%B2/" class="article-date">
	  <time datetime="2021-03-19T07:30:01.000Z" itemprop="datePublished">2021-03-19</time>
	</a>
</span>
        
  <span class="article-category">
    <i class="icon icon-folder"></i>
    <a class="article-category-link" href="/blog/categories/%E5%89%8D%E7%AB%AF%E8%87%AA%E5%8A%A8%E5%8C%96/">前端自动化</a>
  </span>

        

        

        <span class="post-comment"><i class="icon icon-comment"></i> <a href="/blog/2021/03/19/gitee-jenkins%E8%87%AA%E5%8A%A8%E5%8C%96%E6%9E%84%E5%BB%BA%E9%83%A8%E7%BD%B2/#comments" class="article-comment-link">评论</a></span>
        
      </div>
    </div>
    <div class="article-entry marked-body" itemprop="articleBody">
      
        <h3 id="前端自动化部署"><a href="#前端自动化部署" class="headerlink" title="前端自动化部署"></a>前端自动化部署</h3><h3 id="gitee-Jenkins自动构建前端项目并部署到服务器"><a href="#gitee-Jenkins自动构建前端项目并部署到服务器" class="headerlink" title="gitee + Jenkins自动构建前端项目并部署到服务器"></a>gitee + Jenkins自动构建前端项目并部署到服务器</h3><ul>
<li>Gitea 用于构建 Git 局域网服务器，Jenkins 是 CI/CD 工具，用于部署前端项目。</li>
</ul>
<h3 id="配置Gitee"><a href="#配置Gitee" class="headerlink" title="配置Gitee"></a>配置Gitee</h3><ul>
<li>下载<a target="_blank" href="https://dl.gitea.io/gitea" rel="nofollow noopener">Gitea</a>，选择版本，例如：gitea-1.13-windows-4.0-amd64.exe 下载。</li>
<li>下载完后，新建一个目录（例如 gitea），将下载的 Gitea 软件放到该目录下，双击运行。<br><img src="/blog/images/gitee1.png" alt="gitee运行成功" title="gitee运行成功"> </li>
<li>打开 localhost:3000 就能看到 Gitea 已经运行在你的电脑上了。</li>
<li>点击注册，第一次会弹出一个初始配置页面，数据库选择 SQLite3。另外把 localhost 改成你电脑的局域网地址，例如我的电脑 IP 为 192.168.0.118。<ul>
<li>查看电脑IP的方法：快捷键：win + r 打开运行，输入cmd，回车，在终端中输入命令：ipconfig/all 即可查看本地电脑IP</li>
</ul>
</li>
</ul>
<p><img src="/blog/images/gitee1.png" alt="gitee初始化配置" title="gitee初始化配置"> </p>
<ul>
<li><p>初始化配置信息填写完毕，点击立即安装</p>
</li>
<li><p>安装成功后，会来到登录页面，点击立即注册，第一个注册的用户将会成为管理员</p>
</li>
<li><p>打开 Gitea 的安装目录，找到 custom\conf\app.ini，在里面加上一行代码 START_SSH_SERVER = true。这时就可以使用 ssh 进行 push 操作了。</p>
</li>
<li><p><img src="/blog/images/serverSSH.png" alt="serverSSH" title="serverSSH"></p>
<ul>
<li>如果使用 http 的方式无法克隆项目，请取消 git 代理。<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">git config --<span class="built_in">global</span> --unset http.proxy</span><br><span class="line">git config --<span class="built_in">global</span> --unset https.proxy</span><br></pre></td></tr></table></figure>

</li>
</ul>
</li>
</ul>
<h3 id="配置Jenkins"><a href="#配置Jenkins" class="headerlink" title="配置Jenkins"></a>配置Jenkins</h3><h2 id="如果想要重新安装Jenkins，直接删除C-Windows-System32-config-systemprofile-AppData-Local目录下的Jenkins文件，然后重新安装Jenkins即可"><a href="#如果想要重新安装Jenkins，直接删除C-Windows-System32-config-systemprofile-AppData-Local目录下的Jenkins文件，然后重新安装Jenkins即可" class="headerlink" title="如果想要重新安装Jenkins，直接删除C:\Windows\System32\config\systemprofile\AppData\Local目录下的Jenkins文件，然后重新安装Jenkins即可"></a>如果想要重新安装Jenkins，直接删除C:\Windows\System32\config\systemprofile\AppData\Local目录下的Jenkins文件，然后重新安装Jenkins即可</h2><ul>
<li>需提前安装JDK</li>
<li>下载<a target="_blank" href="https://www.jenkins.io/zh/download/" rel="nofollow noopener">Jenkins</a></li>
</ul>
<p><img src="/blog/images/Jenkins-download.png" alt="Jenkins-download" title="Jenkins-download"></p>
<ul>
<li>安装过程中遇到 Logon Type 时，选择第一个。</li>
</ul>
<p><img src="/blog/images/Logon.png" alt="Logon" title="Logon"></p>
<ul>
<li>端口默认为 8080，点击test port，最后再点击next。安装完会自动打开 <a target="_blank" rel="noopener" href="http://localhost:8000/">http://localhost:8000</a> 网站，这时需要等待一会，进行初始化。</li>
<li>选择jdk或者jre，点击next</li>
</ul>
<p><img src="/blog/images/seljdk.png"></p>
<ul>
<li><p>点击next，点击安装，安装完会自动打开 <a target="_blank" rel="noopener" href="http://localhost:8088/">http://localhost:8088</a> 网站，这时需要等待一会，进行初始化。</p>
</li>
<li><p>按照提示找到对应的文件（直接复制路径在我的电脑中打开），其中有管理员密码。<br><img src="/blog/images/slor.png" alt="slor" title="slor"></p>
</li>
<li><p>安装插件</p>
</li>
<li><p>创建管理员用户，点击完成并保存，然后一路下一步。</p>
</li>
<li><p>配置完成后自动进入首页，这时点击 Manage Jenkins -&gt; Manage plugins 安装插件。<br><img src="/blog/images/plugin.png" alt="安装插件" title="安装插件"></p>
</li>
<li><p>点击 Manage Jenkins，选择Manage plugins，选择Available，在搜索框中输入 nodejs，搜索插件，然后安装。<br><img src="/blog/images/selPlugin.png" alt="安装插件" title="安装插件"><br><img src="/blog/images/d.png" alt="安装插件" title="安装插件"></p>
</li>
<li><p style="color:red">如果遇到插件安装失败，解决方法:配置Jenkins更新插件的地址，改为国内镜像(http://mirror.esuni.jp/jenkins/updates/update-center.json)</p>
![插件安装失败的解决方法](/blog/images/G.png "插件安装失败的解决方法")
</li>
<li><h3 style="color:red">重启Jenkins服务，重启：在浏览器后面加上/restart，如：http://localhost:8088/restart，回车，点击yes即可重启</h3>
</li>
<li><p>nodejs安装成功后，需要在Global Tool Configuration 配置 nodejs。如果你的电脑是 win7 的话，nodejs 版本最好不要太高，选择 v12 左右的就行<br><img src="/blog/images/nodejs.png" alt="配置node" title="配置node"></p>
</li>
</ul>
<h3 id="创建静态资源服务器"><a href="#创建静态资源服务器" class="headerlink" title="创建静态资源服务器"></a>创建静态资源服务器</h3><ul>
<li><p>创建一个空目录，在里面执行npm init -y ,初始化项目</p>
</li>
<li><p>安装express：npm i express</p>
</li>
<li><p>创建server.js文件，添加如下代码</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> express = <span class="built_in">require</span>(<span class="string">&#x27;express&#x27;</span>)</span><br><span class="line"><span class="keyword">const</span> app = express()</span><br><span class="line"><span class="keyword">const</span> port = <span class="number">8080</span></span><br><span class="line"></span><br><span class="line">app.use(express.static(<span class="string">&#x27;dist&#x27;</span>))</span><br><span class="line"></span><br><span class="line">app.listen(port, <span class="function">() =&gt;</span> &#123;</span><br><span class="line">    <span class="built_in">console</span>.log(<span class="string">`Example app listening at http://localhost:<span class="subst">$&#123;port&#125;</span>`</span>)</span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure>
</li>
<li><p>它将当前目录下的 dist 文件夹设为静态服务器资源目录，然后执行 node server.js 启动服务器,由于现在没有 dist 文件夹，所以访问网站是空页面</p>
</li>
</ul>
<h3 id="自动构建-部署到服务器"><a href="#自动构建-部署到服务器" class="headerlink" title="自动构建 + 部署到服务器"></a>自动构建 + 部署到服务器</h3><ul>
<li><p>下载 Jenkins 提供的 demo 项目 building-a-multibranch-pipeline-project，然后在你的 Gitea 新建一个仓库，把内容克隆进去，并提交到 Gitea 服务器，该demo项目可以通过在gitee或者github上克隆<br><img src="/blog/images/gitea.png" alt="新建仓库" title="新建仓库"></p>
</li>
<li><p>打开Jenkins首页，点击新建item，创建项目<br><img src="/blog/images/newitem.png" alt="Jenkins创建项目" title="Jenkins创建项目"></p>
</li>
<li><p>选择源码管理，输入你的 Gitea 上的仓库地址。<br><img src="/blog/images/copy.png" alt="Jenkins创建项目" title="Jenkins创建项目"></p>
</li>
<li><p>你也可以尝试一下定时构建，下面这个代码表示每 5 分钟构建一次。<br><img src="/blog/images/auto.png" alt="Jenkins创建项目" title="Jenkins创建项目"></p>
</li>
<li><p>选择你的构建环境，这里选择刚才配置的 nodejs。<br><img src="/blog/images/node.png" alt="Jenkins创建项目" title="Jenkins创建项目"></p>
</li>
<li><p> 点击增加构建步骤，windows 要选 execute windows batch command，linux 要选 execute<br><img src="/blog/images/select.png" alt="windows" title="windows"></p>
</li>
<li><p>输入 npm i &amp;&amp; npm run build &amp;&amp; xcopy .\build* D:\gitee-Jenkins-auto\test\dist\ /s/e/y，这行命令的作用是安装依赖，构建项目，并将构建后的静态资源复制到指定目录 D:\gitee-Jenkins-auto\test\dist\ 。这个目录是静态服务器资源目录<br><img src="/blog/images/dist.png" alt="windows" title="windows"></p>
</li>
<li><p>保存后，返回首页。点击项目旁边的小三角，选择 build now。<br><img src="/blog/images/build.png" alt="build" title="build"></p>
</li>
<li><p>开始构建项目，我们可以点击项目查看构建过程<br><img src="/blog/images/startbuild.png" alt="startbuild" title="startbuild"></p>
</li>
<li><p>构建成功，打开 <a target="_blank" rel="noopener" href="http://localhost:8080/">http://localhost:8080/</a> 看一下结果<br><img src="/blog/images/success.png" alt="success" title="success"></p>
</li>
<li><p>打包成功<br><img src="/blog/images/buildsuccess.png" alt="buildsuccess" title="buildsuccess"></p>
</li>
<li><p>由于刚才设置了每 5 分钟构建一次，我们可以改变一下网站的内容，然后什么都不做，等待一会再打开网站看看<br><img src="/blog/images/resetbuild.png" alt="resetbuild" title="resetbuild"></p>
</li>
<li><p>重新运行server.js，并在浏览器访问</p>
</li>
</ul>
<h3 id="使用pipeline-构建项目"><a href="#使用pipeline-构建项目" class="headerlink" title="使用pipeline 构建项目"></a>使用pipeline 构建项目</h3><ul>
<li><p>使用流水线构建项目可以结合 Gitea 的 webhook 钩子，以便在执行 git push 的时候，自动构建项目</p>
</li>
<li><p>点击首页右上角的用户名，选择设置<br><img src="/blog/images/set.png" alt="set" title="set"></p>
</li>
<li><p>添加 token，记得将 token 保存起来<br><img src="/blog/images/token.png" alt="token" title="token"></p>
</li>
<li><p>打开 Jenkins 首页，点击 新建 Item 创建项目<br><img src="/blog/images/renwu.png" alt="renwu" title="renwu"></p>
</li>
<li><p>点击构建触发器，选择触发远程构建，填入刚才创建的 token<br><img src="/blog/images/shuru.png" alt="shuru" title="shuru"></p>
</li>
<li><p>选择流水线，按照提示输入内容，然后点击保存<br><img src="/blog/images/baocun.png" alt="baocun" title="baocun"></p>
</li>
<li><p>打开 Jenkins 安装目录下的 jenkins.xml 文件，找到 <arguments> 标签，在里面加上 -Dhudson.security.csrf.GlobalCrumbIssuerConfiguration.DISABLE_CSRF_PROTECTION=true。它的作用是关闭 CSRF 验证，不关的话，Gitea 的 webhook 会一直报 403 错误，无法使用。加好参数后，在该目录命令行下输入 jenkins.exe restart 重启 Jenkins<br><img src="/blog/images/22.png" alt="22" title="22"></p>
</li>
<li><p>回到首页，配置全局安全选项。勾上匿名用户具有可读权限，再保存<br><img src="/blog/images/promission.png" alt="promission" title="promission"><br><img src="/blog/images/%E6%8E%88%E6%9D%83.png" alt="授权" title="授权"></p>
</li>
<li><p>打开你的 Gitea 仓库页面，选择仓库设置<br><img src="/blog/images/%E4%BB%93%E5%BA%93%E8%AE%BE%E7%BD%AE.png" alt="仓库设置" title="仓库设置"></p>
</li>
<li><p>点击管理 web 钩子，添加 web 钩子，钩子选项选择 Gitea</p>
</li>
<li><p>目标 URL 按照 Jenkins 的提示输入内容。然后点击添加 web 钩子<br><img src="/blog/images/%E6%B7%BB%E5%8A%A0.png" alt="添加" title="添加"></p>
</li>
<li><p>点击创建好的 web 钩子，拉到下方，点击测试推送。不出意外，应该能看到推送成功的消息，此时回到 Jenkins 首页，发现已经在构建项目了</p>
</li>
<li><p>由于没有配置 Jenkinsfile 文件，此时构建是不会成功的。所以接下来需要配置一下 Jenkinsfile 文件。将以下代码复制到你 Gitea 项目下的 Jenkinsfile 文件。jenkins 在构建时会自动读取文件的内容执行构建及部署操作</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">pipeline &#123;</span><br><span class="line">    agent any</span><br><span class="line">    stages &#123;</span><br><span class="line">        <span class="function"><span class="title">stage</span>(<span class="params"><span class="string">&#x27;Build&#x27;</span></span>)</span> &#123;</span><br><span class="line">            steps &#123;  <span class="comment">// window 使用 bat， linux 使用 sh</span></span><br><span class="line">                bat <span class="string">&#x27;npm i&#x27;</span></span><br><span class="line">                bat <span class="string">&#x27;npm run build&#x27;</span></span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="function"><span class="title">stage</span>(<span class="params"><span class="string">&#x27;Deploy&#x27;</span></span>)</span> &#123;</span><br><span class="line">            steps &#123;</span><br><span class="line">                bat <span class="string">&#x27;xcopy .\\build\\* D:\\node-server\\dist\\ /s/e/y&#x27;</span> <span class="comment">// 这里需要改成你的静态服务器资源目录</span></span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>














</li>
</ul>

      
    </div>
    <div class="article-footer">
      <!-- <blockquote class="mt-2x"> -->
  <!-- <ul class="post-copyright list-unstyled">
    
    <li class="post-copyright-link hidden-xs">
      <strong>本文链接：</strong>
      <a href="https://gitee.com/Yu-Luoboke/2021/03/19/gitee-jenkins%E8%87%AA%E5%8A%A8%E5%8C%96%E6%9E%84%E5%BB%BA%E9%83%A8%E7%BD%B2/" title="gitee-jenkins自动化构建部署" target="_blank" rel="external">https://gitee.com/Yu-Luoboke/2021/03/19/gitee-jenkins%E8%87%AA%E5%8A%A8%E5%8C%96%E6%9E%84%E5%BB%BA%E9%83%A8%E7%BD%B2/</a>
    </li>
    
    <li class="post-copyright-license">
      <strong>版权声明： </strong> 本博客所有文章除特别声明外，均采用 <a href="http://creativecommons.org/licenses/by/4.0/deed.zh" target="_blank" rel="external">CC BY 4.0 CN协议</a> 许可协议。转载请注明出处！
    </li>
  </ul> -->
<!-- </blockquote> -->


<!-- <div class="panel panel-default panel-badger">
  <div class="panel-body">
    <figure class="media">
      <div class="media-left">
        <a href="http://yu-luoboke.gitee.io/blog" target="_blank" class="img-burn thumb-sm visible-lg">
          <img src="/blog/images/avatar.jpg" class="img-rounded w-full" alt="">
        </a>
      </div>
      <div class="media-body">
        <h3 class="media-heading"><a href="http://yu-luoboke.gitee.io/blog" target="_blank"><span class="text-dark">雨落</span><small class="ml-1x">前端开发-奋斗青年</small></a></h3>
        <div>前端经验总结。</div>
      </div>
    </figure>
  </div>
</div> -->


    </div>
  </article>
  
    

  
</div>

  <nav class="bar bar-footer clearfix" data-stick-bottom>
  <div class="bar-inner">
  
  <ul class="pager pull-left">
    
    <li class="prev">
      <a href="/blog/2021/03/31/%E7%A7%BB%E5%8A%A8%E7%AB%AF%E9%80%82%E9%85%8D/" title="移动端适配"><i class="icon icon-angle-left" aria-hidden="true"></i><span>&nbsp;&nbsp;上一篇</span></a>
    </li>
    
    
    <li class="next">
      <a href="/blog/2021/03/09/webpack%E6%9E%84%E5%BB%BAvue%E9%A1%B9%E7%9B%AE/" title="webpack构建vue项目"><span>下一篇&nbsp;&nbsp;</span><i class="icon icon-angle-right" aria-hidden="true"></i></a>
    </li>
    
    
  </ul>
  
  
  
  <div class="bar-right">
    
  </div>
  </div>
</nav>
  


</main>

  <footer class="footer" itemscope itemtype="http://schema.org/WPFooter">
	
	
    <ul class="social-links">
    	
        <li><a href="http://yu-luoboke.gitee.io/blog" target="_blank" title="Github" ><i class="icon icon-github"></i></a></li>
        
    </ul>

    <div class="copyright">
    	
        &copy; 2024 lianghongming
        
        <div class="publishby">
        	Theme by <a href="https://gitee.com/Yu-Luoboke/blog" target="_blank"> blog </a>base on <a href="https://gitee.com/Yu-Luoboke/blog" target="_blank">pure</a>.
        </div>
    </div>
</footer>
  <script src="//cdn.jsdelivr.net/npm/jquery@1.12.4/dist/jquery.min.js"></script>
<script>
window.jQuery || document.write('<script src="js/jquery.min.js"><\/script>')
</script>

<script src="/blog/js/plugin.min.js"></script>


<script src="/blog/js/application.js"></script>


    <script>
(function (window) {
    var INSIGHT_CONFIG = {
        TRANSLATION: {
            POSTS: '文章',
            PAGES: '页面',
            CATEGORIES: '分类',
            TAGS: '标签',
            UNTITLED: '(未命名)',
        },
        ROOT_URL: '/blog/',
        CONTENT_URL: '/blog/content.json',
    };
    window.INSIGHT_CONFIG = INSIGHT_CONFIG;
})(window);
</script>

<script src="/blog/js/insight.js"></script>






   









</body>
</html>